<head>
    <link href="${ctx}/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <link href="${ctx}/font-awesome/3.0.0/css/font-awesome.min.css" rel="stylesheet">
    <link href="${ctx}/css/index.css" rel="stylesheet">
    <link href="${ctx}/bootstrap-table/1.12.0/bootstrap-table.min.css" rel="stylesheet">
    <script src="${ctx}/jquery/2.1.4/jquery.min.js"></script>
    <script src="${ctx}/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="${ctx}/bootstrap-table/1.12.0/bootstrap-table.min.js"></script>
    <script src="${ctx}/bootstrap-table/1.12.0/locale/bootstrap-table-zh-CN.min.js"></script>
    <script src="${ctx}/bootstrap-table/1.12.0/extensions/export/bootstrap-table-export.min.js"></script>
    <script src="${ctx}/js/extends.js"></script>
    <script src="${ctx}/layui/layui.all.js"></script>
    <script src="${ctx}/js/util.js"></script>
    <link href="${ctx}/layui/css/layui.css" rel="stylesheet">
</head>
<title>师徒统计分页</title>
<div class="lay-box">
    <form class="layui-form" action="" style="margin-top: 10px">
        <div class="layui-inline" style="margin: 0 0 8px 20px;">
            <label class="layui-form-label" style="width: 95px">起始时间</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" id="star" placeholder="请选择时间">
            </div>
        </div>
        <div class="layui-inline" style="margin: 0 0 8px 20px;">
            <label class="layui-form-label" style="width: 95px">结束时间</label>
            <div class="layui-input-inline">
                <input type="text" class="layui-input" id="end" placeholder="请选择时间">
            </div>
        </div>
        <div style="width: 150px;display: inline-block;margin: 0 0 8px 20px;">

                <select name="sdkKey" id="sdkKey" style="width: 300px">
                    <option value="all">数据源</option>
                    <#list item as list>
                        <option value="${list.sdkKey}">${list.taskName}</option>
                    </#list>
                </select>

        </div>


        <div style="width: 150px;display: inline-block;margin: 0 0 8px 20px;">
            <select name="category" id="category" lay-verify="" style="width:300px">
                <option value=2>全部用户</option>
                <option value=0>老用户</option>
                <option value=1>新用户</option>
            </select>
        </div>


    </form>

    <span onclick="search()" class="btn btn-info" style="height: 38px;margin-left: 10px;font-size: 14px">查询</span>

    <table class="table table-border table-bordered table-hover table-bg table-sort" id="layTable"
           lay-filter="tableFilter">

    </table>
</div>

<style>
    .lay-box {
        padding: 8px 12px;
    }

    .layui-form-checkbox[lay-skin=primary] i {
        top: 5px;
    }
</style>
<script type="text/html" id="barDemo">

    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>


<!--请在下方写此页面业务相关的脚本-->
<script type="text/html" id="switchTpl">
    <!-- 这里的 checked 的状态只是演示 -->
    <input type="checkbox" name="sex" value="{{d.id}}" lay-skin="switch" lay-text="启用|禁用" lay-filter="sexDemo" {{
           d.enable== 1 ? 'checked' : '' }}>
</script>

<script type="text/javascript">
    var category = 2;
    layui.use('laydate', function () {
        var laydate = layui.laydate;
        laydate.render({
            elem: '#star'
            , type: 'datetime'
            , format: 'yyyyMMdd'

        });
        laydate.render({
            elem: '#end'
            , type: 'datetime'
            , format: 'yyyyMMdd'
        });
        laydate.render({
            elem: '#last'
            , type: 'date'
            , format: 'yyyy-MM-dd'
        });
    });
    form = layui.form;
    form.render();
    function search() {
        var star = $("#star").val();
        var end = $("#end").val();
        var appStore = $("#appStore").val();
        var category = $("#category").val();
        var sdkKey = $("#sdkKey").val();

        if (appStore !== "all" && category !== "2" && sdkKey !== "all") {
            type = 0;
        } else {
            type = 1;
        }


        var startDate = "";
        var endDate = "";
        var searchKey = "";
        var tableIns;
        var ids = "";
        var form;
        var table = "cences_master";
        layui.use('table', function () {
            tableIns = layui.table,

            tableIns.render({
                elem: '#layTable'
                ,
                url: '/sys/cencesearnday/apru'

                , done: function (res, curr, count) {
                    //如果是异步请求数据方式，res即为你接口返回的信息。
                    //如果是直接赋值的方式，res即为：{data: [], count: 99} data为当前页数据、count为数据总长度
                    console.log(res);

                    //得到当前页码
                    console.log(curr);

                    //得到数据总量
                    console.log(count);
                },
                method: 'POST'
                ,
                where: {likeBrand:$("#likeBrand").val(),star: star, end: end, appStore: appStore, category: category, type: type, sdkKey: sdkKey}
                ,
                id: 'dataTableId'
                ,
                cols: [[
                    {type: 'checkbox', field: 'id'}
                    , {
                        field: 'time',
                        title: '记录日期',
                        width: 150,
                        align: 'center',
                        sort: true,
                        templet: function (data) {
                            if (data.time < 0) {
                                return '统计';
                            } else {
                                return data.time;
                            }
                        }
                    }, {
                        field: 'vivo',
                        title: 'VIVO',
                        width: 150,
                        align: 'center',
                        sort: true,
                        templet: function (data) {
                            return GetPercent(data.vivo, data.allTotal);
                        }
                    }, {
                        field: 'oppo',
                        title: 'oppo',
                        width: 150,
                        align: 'center',
                        sort: true,
                        templet: function (data) {
                            return GetPercent(data.oppo, data.allTotal);
                        }
                    }, {
                        field: 'huawei',
                        title: 'huawei',
                        width: 150,
                        align: 'center',
                        sort: true,
                        templet: function (data) {
                            return GetPercent(data.huawei, data.allTotal);
                        }
                    }, {
                        field: 'xiaomi',
                        title: 'xiaomi',
                        width: 150,
                        align: 'center',
                        sort: true,
                        templet: function (data) {
                            return GetPercent(data.xiaomi, data.allTotal);
                        }
                    }, {
                        field: 'meizu',
                        title: 'meizu',
                        width: 150,
                        align: 'center',
                        sort: true,
                        templet: function (data) {
                            return GetPercent(data.meizu, data.allTotal);
                        }
                    }, {
                        field: '360',
                        title: 'sll',
                        width: 150,
                        align: 'center',
                        sort: true,
                        templet: function (data) {
                            return GetPercent(data.sll, data.allTotal);
                        }
                    }, {
                        field: '应用宝',
                        title: 'yyb',
                        width: 150,
                        align: 'center',
                        sort: true,
                        templet: function (data) {
                            return GetPercent(data.yyb, data.allTotal);
                        }
                    }, {
                        field: '小啄',
                        title: 'xiaozhuo',
                        width: 150,
                        align: 'center',
                        sort: true,
                        templet: function (data) {
                            return GetPercent(data.xiaozhuo, data.allTotal);
                        }
                    }, {
                        field: 'csj*',
                        title: 'csj',
                        width: 150,
                        align: 'center',
                        sort: true,
                        templet: function (data) {
                            return GetPercent(data.csj, data.allTotal);
                        }
                    }, {
                        field: 'gdt*',
                        title: 'gdt',
                        width: 150,
                        align: 'center',
                        sort: true,
                        templet: function (data) {
                            return GetPercent(data.gdt, data.allTotal);
                        }
                    }


                    , {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 150, align: 'center'}

                ]]
                ,
                page: true
            });

        });
    }

    function GetPercent(num, total) {
        /// <summary>
        /// 求百分比
        /// </summary>
        /// <param name="num">当前数</param>
        /// <param name="total">总数</param>
        num = parseFloat(num);
        total = parseFloat(total);
        if (isNaN(num) || isNaN(total)) {
            return "-";
        }
        return total <= 0 ? "0%" : (Math.round(num / total * 10000) / 100.00) + "%";
    }

    function gradeEdit() {
        layer_show("新增", "/sys/cencesearnday/add", "650", "600");
    }

    function showmsg(msg) {
        layer.msg(msg)
    }

    function commonenable(id, status) {
        $.ajax({
            url: "/common/commonSwitch",
            type: 'post',
            data: {"table": table, "id": id, "status": status, "feild": "has_deleted"},
            async: false,
            dataType: "json",
            success: function (req) {
                if (req.success) {
                    search();
                    layer.msg(req.message, {icon: 1})
                } else {
                    layer.msg(req.message, {icon: 2})
                }
            }
        });
    }


</script>
<!--/请在上方写此页面业务相关的脚本-->
